package com.insideClass.TypeMessage.reflect;

interface Interface{
    /**
     * doSomething
     */
    void doSomething();

    /**
     * somethingElse
     * @param arg
     */
    void somethingElse(String arg);
}
class RealObject implements Interface{

    @Override
    public void doSomething() {
        System.out.println("doSomething");
    }

    @Override
    public void somethingElse(String arg) {
        System.out.println("somethingElse"+arg);
    }
}
class Simpleproxy implements Interface{
    private Interface proxied;

    public Simpleproxy(Interface proxied) {
        this.proxied = proxied;
    }

    @Override
    public void doSomething() {
        System.out.println("SimpleProxy doSomething");
        proxied.doSomething();
    }

    @Override
    public void somethingElse(String arg) {
        System.out.println("SimpleProxy somethingElse"+arg);
        proxied.somethingElse(arg);
    }
}

/**
 * 动态代理
 * 设计模式之一
 * @author 13699
 */
public class SimpleProxyDemo {
    public static void consumer(Interface iface){
        iface.doSomething();
        iface.somethingElse("bonobo");
    }

    public static void main(String[] args) {
        consumer(new RealObject());
        consumer(new Simpleproxy(new RealObject()));
    }
}
